package com.base.leetcode;

import com.base.dataStructure.Tree.TreeNode;

/**
 * @Author: hdhao
 * @Create: 2023/4/5 - 18:56
 * @Version: v1.0
 */
//对称二叉树
public class Leetcode101 {

    public boolean isSummetric(TreeNode root) {
        return check(root.left, root.right);
    }

    private boolean check(TreeNode left, TreeNode right) {
        if (left == null && right == null) {
            return true;
        }
        //走到这里说明left和right不能同时为null
        if (right == null || left == null) {
            return false;
        }
        if (left.val != right.val) {
            return false;
        }
        //递归检查
        return check(left.left,right.right) && check(left.right, right.left);
    }
}
